//处理系统设置模块表格列头、列前操作js文件(xiaogq)

/**
 * 添加自定义实体方法
 * @author       xiaogq
 * @param node
 */
function addEntity(node){
    var title = $(node).attr("title");
    var url = $(node).attr("url");
    var entityId = $(node).attr("tableCode");
    var node = {id: "add"+entityId, text: "新建:"+title, url:url};
    parent.showTab(node);
}

/**
 * 对象编辑方法
 * @author       xiaogq
 * @param node
 */
function entityUpdate(node){
    //获取实体id
    var entityId = $(node).attr("id");
    var title = "对象"+$(node).attr("title");
    var url = $(node).attr("url");
    if(url.indexOf("?") != -1){
        url = url+"&entityId="+entityId;
    }else{
        url = url+"?entityId="+entityId;
    }
    var node = {id: "edit"+entityId, text:title, url:url};
    parent.showTab(node);
}

/**
 * 对象删除方法
 * @author       xiaogq
 * @param node
 */
function entityDelete(node){
    //获取实体id
    var entityId = $(node).attr("id");
    if(confirm(" 确定要删除实体吗")){
        $.ajax({
            url : getRootPath()+"/"+Constants.delEntityUrl+"?entityId="+entityId,
            type :'GET',
            success:function(data){
                var info = data.info;
                if(info == "error"){
                    alert("实体被使用");
                    return;
                }else if( info != "success" ){
                    alert(info);
                    return;
                }
                $("#entity_table2").bootstrapTable("refresh");
            },
            error : function(){
                alert("实体被使用");
            }
        });
    }
}

/**
 * 对象管理列表属性设置方法
 * @author       xiaogq
 * @param node
 */
function entityfieldList(node){
    //获取实体id
    var entityId = $(node).attr("id");
    //获得实体名称
    var name = $(node).attr("name");
    //获得操作按钮中文名称
    var title = $(node).attr("title");
    var url = $(node).attr("url");
    if(url.indexOf("?") != -1){
        url = url+"&entityId="+entityId;
    }else{
        url = url+"?entityId="+entityId;
    }
    var node = {id: "entityfield"+entityId, text: title, url:url};
    //打开tabls标签
    parent.showTab(node);
}

/**
 * 属性设置列表页添加自定义字段方法
 * @author       xiaogq
 * @param node
 */
function addField(node){
    var entityId = $(node).attr("tableCode");
    var title = $(node).attr("title");
    var url = $(node).attr("url");
    if(url.indexOf("?") != -1){
        url = url+"&entityId="+entityId+"&title="+title;
    }else{
        url = url+"?entityId="+entityId+"&title="+title;
    }
    var node = {id: "addField"+entityId, text: "新建:"+title, url:url};
    //打开tabls标签
    //parent.addMenu(node,{title:title+":新建自定义字段",url:url,type:"R"});
    parent.showTab(node);
}

/**
 * 属性设置列表页编辑自定义字段方法
 * @author       xiaogq
 * @param node
 */
function editField(node){
    //获得实体id
    var entityId = $("#tableCode").val();
    //获取字段id
    var fieldId = $(node).attr("id");
    var title = $(node).attr("title");
    var url = $(node).attr("url");
    if(url.indexOf("?") != -1){
        url = url+"&entityId="+entityId+"&fieldId="+fieldId;
    }else{
        url = url+"?entityId="+entityId+"&fieldId="+fieldId;
    }
    var node = {id: "editField"+entityId, text:"编辑自定义字段", url:url};
    //打开tabls标签
    //parent.addMenu(node,{title:title+":编辑自定义字段",url:url,type:"R"});
    parent.showTab(node);
}

/**
 * 字段属性级控制
 * @author       xiaogq
 * @param node
 */
function fieldControl(node) {
    //获得实体id
    var entityId = $("#tableCode").val();
    //获取字段id
    var fieldId = $(node).attr("id");
    var fieldName = $(node).attr("name");
    var title = $(node).attr("title");
    var url = $(node).attr("url");
    if(url.indexOf("?") != -1){
        url = url+"&entityId="+entityId+"&fieldId="+fieldId+"&fieldName="+fieldName;
    }else{
        url = url+"?entityId="+entityId+"&fieldId="+fieldId+"&fieldName="+fieldName;
    }
    var node = {id: "fieldControl"+entityId, text: title, url:url};
    //打开tabls标签
    //parent.addMenu(node,{title:title+":"+fieldName,url:url,type:"R"});
    parent.showTab(node);
}

/**
 * 单选、下拉、下拉多选定义枚举值方法
 * @author       xiaogq
 * @param node
 */
function addSinglebox(node){
    //获得实体id
    var entityId = $("#tableCode").val();
    //获取字段id
    var fieldId = $(node).attr("id");
    var fieldName = $(node).attr("name");
    var title = $(node).attr("title");
    var url = $(node).attr("url");
    if(url.indexOf("?") != -1){
        url = url+"&entityId="+entityId+"&fieldId="+fieldId+"&fieldName="+fieldName;
    }else{
        url = url+"?entityId="+entityId+"&fieldId="+fieldId+"&fieldName="+fieldName;
    }
    var node = {id: "addSinglebox"+entityId, text: title, url:url};
    //打开tabls标签
    //parent.addMenu(node,{title:fieldName+":"+title,url:url,type:"R"});
    parent.showTab(node);
}

/**
 * 枚举字段定义约束关系方法
 * @author       xiaogq
 * @param node
 */
function fieldRestrict(node){
    //获得实体id
    var entityId = $("#tableCode").val();
    //获取字段id
    var fieldId = $(node).attr("id");
    var fieldName = $(node).attr("name");
    var title = $(node).attr("title");
    var url = $(node).attr("url");
    if(url.indexOf("?") != -1){
        url = url+"&entityId="+entityId+"&fieldId="+fieldId;
    }else{
        url = url+"?entityId="+entityId+"&fieldId="+fieldId;
    }
    var node = {id: "fieldRestrict"+entityId, text: title, url:url};
    //打开tabls标签
    //parent.addMenu(node,{title:fieldName+":"+title,url:url,type:"R"});
    parent.showTab(node);
}

/**
 * 设置枚举值约束关系方法
 * @author       xiaogq
 * @param node
 */
function restricterSet(node){
    //获得实体id
    var entityId = $("#tableCode").val();
    var fieldId = $(node).attr('childid');
    var fieldLocal = $(node).attr('childLocal');
    var resFieldId = $(node).attr('nodeid');
    var resFieldLocal = $(node).text();
    var url = "FieldRecord/fieldRestrictedSet.do?entityId="+entityId+"&fieldId="+fieldId+"&fieldLocal="+fieldLocal+"&resFieldId="+resFieldId+"&resFieldLocal="+resFieldLocal;
    //打开tabls标签
    var node = {id: "restricterSet"+entityId, text: resFieldLocal+":约束关系", url:url};
    //parent.addMenu(node,{title:resFieldLocal+":约束关系",url:url,type:"R"});
    parent.showTab(node);
}

/**
 * 属性设置列表页删除自定义字段方法
 * @author       xiaogq
 * @param node
 */
function deleteField(node){
    var fieldId = $(node).attr('id');
    var url = $(node).attr("url");
    if(url.indexOf("?") != -1){
        url = url+"&fieldId="+fieldId;
    }else{
        url = url+"?fieldId="+fieldId;
    }
    if(confirm("确定要删除本字段吗" )){
        $.ajax({
            url : getRootPath()+"/"+url,
            type :'GET',
            success:function(data){
                if(data.hasData){
                    alert("字段中有数据,请先删除");
                    return false;
                }
                $("#field_table2").bootstrapTable("refresh");
            },
            error  : function(){
                alert("字段被使用");
            }
        });
    }
}

/**
 * 属性设置列表页自定义字段排序方法
 * @author       xiaogq
 * @param node
 */
function sortFields(node){
    var entityId = $(node).attr("tableCode");
    var title = $(node).attr("title")+":"+"字段排序";
    var url = $(node).attr("url");
    if(url.indexOf("?") != -1){
        url = url+"&entityId="+entityId;
    }else{
        url = url+"?entityId="+entityId;
    }
    var node = {id: "sortFields"+entityId, text: title, url:url};
    //打开tabls标签
    //parent.addMenu(node,{title:title,url:url,type:"R"});
    parent.showTab(node);
}

/**
 * 实体操作列表根据条件搜索方法
 * @author       xiaogq
 */
function queyEntityOperations(){
    //获取是否是系统操作标识(1:是，0：否)
    var sysOperation = $(".operation_span").attr("sysOperation");
    //获得操作名称
    var name = $("#operation_name").val();
    //获得操作按钮显示位置
    var showHere = $("#is_here").val();
    //合并搜索条件
    var filter = {sysOperation : sysOperation,name : name,showHere : showHere};
    $("#entity_table"+sysOperation).bootstrapTable("refresh", {query:filter});
}

/**
 *
 * 添加实体操作方法
 * @author       xiaogq
 * @param node
 */
function addEntityOperation(node){
    var title = $(node).attr("title");
    var url = $(node).attr("url");
    var entityId = $(node).attr("tableCode");
    var node = {id: "add"+entityId, text: "新建:"+title, url:url};
    parent.showTab(node);
}

/**
 * 编辑实体操作方法
 * @author       xiaogq
 * @param node
 */
function entityOperationUpdate(node){
    //alert("编辑实体操作!");
    var operationId = $(node).attr("id");
    var title = $(node).attr("title");
    var url = $(node).attr("url");
    var entityId = $(node).attr("tableCode");
    if(url.indexOf("?") != -1){
        url = url+"&operationId="+operationId;
    }else{
        url = url+"?operationId="+operationId;
    }
    var node = {id: "edit"+entityId, text: "编辑:"+title, url:url};
    parent.showTab(node);
}

/**
 * 删除实体操作方法
 * @author       xiaogq
 * @param node
 */
function entityOperationDelete(node){
    //获取是否是系统操作标识(1:是，0：否)
    var sysOperation = $(".operation_span").attr("sysOperation");
    //获取当前记录id
    var id = $(node).attr("id");
    if(confirm("确定要删除该条数据吗？")){
        $.ajax({
            type: 'POST',
            contentType: 'application/json',
            url: getRootPath()+"/"+Constants.deleteEntityOperationUrl+"?id="+id,
            dataType: 'json',
            success: function(data) {
                //重新刷新表格数据
                queyEntityOperations();
            },
            error: function(data) {
                alert("删除数据发生错误!");
            }
        });
    }
}

/**
 * 后台实体列表布局、过滤条件布局通用方法
 * @author       xiaogq
 * @param node
 */
function editEntityLayout(node){
    //获取实体id
    var entityId = $(node).attr("id");
    //获得实体名称
    var name = $(node).attr("name");
    //获得操作按钮中文名称
    var buTitle = $(node).attr("title");
    var url = $(node).attr("url");
    if(url.indexOf("?") != -1){
        url = url+"&entityId="+entityId;
    }else{
        url = url+"?entityId="+entityId;
    }
    var node = {id: "editEntityLayout"+entityId, text: "编辑:"+buTitle, url:url};
    //打开tabls标签
    parent.showTab(node);
    //parent.addMenu(node,{title:name+":"+buTitle,url:url,type:"R"});
}

